home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / fgdemo10.zip / FGDEMO.C < prev    next >
Text File  |  1991-10-05  |  14KB  |  485 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  main.c -- Fastgraph and Fastgraph/Light demo program v 1.0          *
  4. *                                                                      *
  5. *  This program is provided without warranty of any kind.  It may      *
  6. *  be distributed freely as long as the files are not modified.  You   *
  7. *  may use this source code in your own applications as long as it     *
  8. *  clearly understood that we are not responsible for any bugs in      *
  9. *  this code or in your code.  Use this code freely, use it in good    *
  10. *  health, but use it at your own risk.  Further disclaimers are       *
  11. *  listed at the end of this file.                                     *   
  12. *                                                                      *
  13. *  This program requires Fastgraph or Fastgraph/Light to link          *
  14. *  I compiled this program using the MSC 5.1 medium memory model       *
  15. *                                                                      *
  16. \**********************************************************************/
  17.  
  18. #include "defs.h"
  19.  
  20. int  menu_top;
  21. int  menu_bottom;
  22.  
  23. char matrix1[] = {0xAA,0x55,0xAA,0x55};
  24. char matrix2[] = {0x24,0x92,0x24,0x92};
  25.  
  26. /**********************************************************************\
  27. *                                                                      *
  28. *                                 main                                 *
  29. *                                                                      *
  30. \**********************************************************************/
  31.  
  32. void main()
  33. {
  34.    unsigned char key, aux;
  35.    int mousex, mousey, count;
  36.    register int i;
  37.    int current;
  38.  
  39.    /* initialize the video environment */
  40.  
  41.    initialize();
  42.  
  43.    /* read the 8pt and 14pt fonts */
  44.  
  45.    get_font();
  46.  
  47.    /* draw the screen on the hidden page and copy it to the visual page */
  48.  
  49.    draw_screen();
  50.    fg_restore(0,xlimit,0,ylimit);
  51.  
  52.    /* begin the main program loop */
  53.  
  54.    current = 0;
  55.    while (TRUE)
  56.    {
  57.       fg_mousevis(ON);
  58.       fg_waitfor(2);
  59.  
  60.       /* intercept a keystroke */
  61.  
  62.       fg_intkey(&key,&aux);
  63.       if (key == ESC)
  64.       {
  65.          exit_program();
  66.          continue;
  67.       }
  68.       else if (aux == RIGHT_ARROW)
  69.       {
  70.          current++;
  71.          if (current == ITEMS)
  72.             current = 0;
  73.       }
  74.       else if (aux == LEFT_ARROW)
  75.       {
  76.          current--;
  77.          if (current < 0)
  78.             current = ITEMS - 1;
  79.       }
  80.  
  81.       /* display menu according to keystroke pressed */
  82.  
  83.       if (key+aux > 0)
  84.       {
  85.          fg_mousevis(OFF);
  86.          current = horizontal_menu(main_menu,6,current,0,15,15,0);
  87.          if (current == ESC)
  88.          {
  89.             exit_program();
  90.             current = 0;
  91.          }
  92.          fg_mousevis(OFF);
  93.          fg_restore(0,xlimit,menu_top,ylimit);
  94.          fg_mousevis(ON);
  95.       }
  96.  
  97.       /* intercept a mouse click */
  98.  
  99.       fg_mousebut(1,&count,&mousex,&mousey);
  100.       if (count > 0 && BETWEEN(mousey,menu_top,menu_bottom))
  101.       {
  102.          for (i = 0; i <= ITEMS; i++)
  103.          {
  104.             if (BETWEEN(mousex, mouse_limits[i], mouse_limits[i+1]))
  105.             {
  106.                if (horizontal_menu(main_menu,6,i,0,15,15,0) == ESC)
  107.                   exit_program();
  108.                fg_mousevis(OFF);
  109.                fg_restore(0,xlimit,menu_top,ylimit);
  110.                fg_mousevis(ON);
  111.                break;
  112.             }
  113.          }
  114.       }
  115.    }
  116. }
  117.  
  118. /**********************************************************************\
  119. *                                                                      *
  120. *  draw_screen -- draw the main menu screen on the hidden page         *
  121. *                                                                      *
  122. \**********************************************************************/
  123.  
  124. void draw_screen()
  125. {
  126.    int y1, y2, y3;
  127.  
  128.    /* calculate y coordinates based on screen resolution */
  129.  
  130.    if (mode11 || mode16)
  131.    {
  132.       y1 = 3; y2 = 21; y3 = 38;
  133.    }
  134.    else
  135.    {
  136.       y1 = 1; y2 = 12; y3 = 23;
  137.    }
  138.  
  139.    menu_top = y2 + 1;
  140.    menu_bottom  = y3 + 1;
  141.  
  142.    /* erase the hidden page */
  143.  
  144.    background = 15;
  145.    fg_setpage(hidden);
  146.    fg_erase();
  147.  
  148.    /* draw some rectangles */
  149.  
  150.    fg_setcolor(15);
  151.    fg_rect(0,xlimit,0,ylimit);
  152.  
  153.    fg_setcolor(0);
  154.    fg_rect(0,xlimit,0,y2);
  155.  
  156.    /* draw the large dithered rectangles */
  157.  
  158.    if (mode06 || mode11)
  159.       fg_drect(0,xlimit,y3+1,ylimit,matrix1);
  160.    else
  161.    {
  162.       fg_setcolor(9);
  163.       fg_drect(0,xlimit,0,y2-1,matrix1);
  164.       fg_setcolor(14);
  165.       fg_drect(0,xlimit,y3+1,ylimit,matrix2);
  166.    }
  167.  
  168.    /* put the title in the title bar */
  169.  
  170.    fg_setcolor(15);
  171.    center_pstring("Fastgraph Demo",0,xlimit,y2-1);
  172.  
  173.    fg_setcolor(8);
  174.    draw_box(0,xlimit,0,ylimit);
  175.  
  176.    /* draw some black and grey outlines */
  177.  
  178.    fg_setcolor(7);
  179.    draw_box(1,xlimit-1,scale(1),ylimit-scale(1));
  180.    draw_box(2,xlimit-2,scale(2),ylimit-scale(2));
  181.  
  182.    fg_setcolor(0);
  183.    draw_box(3,xlimit-3,y1,y3);
  184.    draw_box(3,xlimit-3,y1,ylimit-y1);
  185.    draw_box(4,xlimit-4,y1,ylimit-y1);
  186.  
  187.    /* draw those little boxes in the corners */
  188.  
  189.    if (mode06 || mode11)
  190.    {
  191.       fg_drect(5,25,y1+1,y2-1,matrix1);
  192.       fg_drect(xlimit-25,xlimit-5,y1+1,y2-1,matrix1);
  193.    }
  194.    else
  195.    {
  196.       fg_setcolor(7);
  197.       fg_rect(5,25,y1+1,y2-1);
  198.       fg_rect(xlimit-25,xlimit-5,y1+1,y2-1);
  199.    }
  200.  
  201.    /* display the horizontal menu */
  202.  
  203.    horizontal_menu(main_menu,-6,0,0,15,15,0);
  204.    fg_setpage(visual);
  205. }
  206.  
  207. /**********************************************************************\
  208. *                                                                      *
  209. *  draw_window -- display a pop-up window                              *
  210. *                                                                      *
  211. \**********************************************************************/
  212.  
  213. void draw_window(xmin,xmax,ymin,ymax,string)
  214. int xmin, xmax, ymin, ymax;
  215. char *string;
  216. {
  217.    register int y;
  218.  
  219.    /* display the window and its border */
  220.  
  221.    fg_setcolor(15);
  222.    fg_rect(xmin,xmax,ymin,ymax);
  223.    fg_setcolor(0);
  224.    draw_box(xmin,xmax,ymin,ymax);
  225.    draw_box(xmin+1,xmax-1,ymin,ymax);
  226.  
  227.    /* display the header bar at the top of the window */
  228.  
  229.    y = ymin + ptsize + 1;
  230.    fg_rect(xmin,xmax,ymin,y+1);
  231.  
  232.    /* dither the header bar for 16 color modes */
  233.  
  234.    if (mode14 || mode16)
  235.    {
  236.       fg_setcolor(7);
  237.       fg_rect(xmin+2,xmin+22,ymin+1,y);
  238.       fg_rect(xmax-22,xmax-2,ymin+1,y);
  239.       fg_setcolor(9);
  240.       fg_drect(xmin+23,xmax-23,ymin+1,y,matrix1);
  241.    }
  242.  
  243.    /* dither the header bar for 2 color modes */
  244.  
  245.    else
  246.    {
  247.       fg_drect(xmin+2,xmin+22,ymin+1,y,matrix1);
  248.       fg_drect(xmax-22,xmax-2,ymin+1,y,matrix1);
  249.    }
  250.  
  251.    /* display the text in the window's header bar */
  252.  
  253.    fg_setcolor(15);
  254.    center_pstring(string,xmin,xmax,y+1);
  255.  
  256.    /* display the window's shadow */
  257.  
  258.    if (mode14 || mode16)
  259.       fg_setcolor(8);
  260.    else
  261.       fg_setcolor(0);
  262.  
  263.    fg_rect(xmin+3,xmax+3,ymax+1,ymax+scale(2));
  264.    fg_rect(xmax+1,xmax+3,ymin+scale(2),ymax);
  265. }
  266.  
  267. /**********************************************************************\
  268. *                                                                      *
  269. *  erase_window -- erase the previously displayed pop-up window        *
  270. *                                                                      *
  271. \**********************************************************************/
  272.  
  273. void erase_window(xmin,xmax,ymin,ymax)
  274. int xmin, xmax, ymin, ymax;
  275. {
  276.    register int x1, x2;
  277.  
  278.    /* restore the original area underneath the window */
  279.  
  280.    x1 = xmin & 0xFFF8;
  281.    x2 = ((xmax+3) & 0xFFF8) + 7;
  282.    fg_mousevis(OFF);
  283.    fg_restore(x1,x2,ymin,ymax+2);
  284.  
  285.    /* redraw the dither pattern on the hidden page */
  286.  
  287.    fg_setpage(hidden);
  288.    if (mode06 || mode11)
  289.       fg_drect(x1,x2,ymin,ymax+2,matrix1);
  290.    else
  291.    {
  292.       fg_setcolor(15);
  293.       fg_rect(x1,x2,ymin,ymax+2);
  294.       fg_setcolor(14);
  295.